package com.bancomer.batch.pig;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import com.bancomer.batch.pojo.Alert;
import com.bancomer.batch.pojo.FileHelper;
import com.bancomer.batch.pojo.PigScript;
import com.bancomer.batch.util.FilesWriter;
import com.bancomer.batch.util.LinuxCommand;
import com.bancomer.batch.util.StringConverter;

public class Pig {
	public static void executePigScript(Alert alert) throws Exception{
		String command = "";
		FileHelper parametersFile = alert.getOutputFiles().get(0);
		String pathParametersFile = parametersFile.getLocalPath()+parametersFile.getName();
		String pigScriptFile = alert.getPigScript().getPath()+alert.getPigScript().getName();
		File f = new File(pigScriptFile);
		if(f.exists()==false) throw new Exception("The file: "+pigScriptFile+" not exist!");
		if(f.length()==0) throw new Exception("The file: "+pigScriptFile+" is empty!");
		command = "pig -param_file "+pathParametersFile+" -x mapreduce "+pigScriptFile;
		LinuxCommand.execute(command,true);
	}
	public static void main(String ... args){
	
	}
}
